

var   groupId;
/**
 * 初始化页面
 */

$(function(){
	initData();
	initLinkGruop();	
})


function initLinkGruop(){
	queryLinkGruop();
}


function initData(){
	groupId=[];
	 for (var i = 0; i < chenckedGroup.length; i++) {
		 groupId.push(""+ chenckedGroup[i].linkmansGroupId);
	}
	 
}


function  queryLinkGruop(){
	var  linkManGroupName=$("#linkManGroupName").val();//关联组类型
	var  type=$("#operate").val();//筛选类型

	var LinkGruop =[{code:'linkmansGroupId',name:'checkBox',width:10},
	           {code:'linkmansGroupName',name:'关联组名称'},
	           {code:'desc',name:'说明'},
	           {code:'remark',name:'备注'}        
	           ];	
	 var  parm={url:basePath+'/radar/config/getGroupList.do',divID:'linkManGroup',afterQuery:'afterselect'};// 常规参数
	 var  data={GroupName:linkManGroupName,operate:type,linkManId:linkManId};    // 赛选条件
     easyQuery(LinkGruop,parm,data);	
     
   
}

function  afterselect(){
	  for (var i = 0; i < groupId.length; i++) {
		  $("input[type='checkbox'][nodeId='"+groupId[i]+"']").prop("checked", true);
	}
}

// 保存绑定的设备
function savelinkGroups(){
     var checkBox='';
	for (var i = 0; i < groupId.length; i++) {
		checkBox=checkBox+groupId[i]+',';
	}
	if(checkBox.length>0){
		checkBox=checkBox.substring(0,(checkBox.length-1));
	}

	$.ajax({
		url:basePath+"/radar/config/savelinkGroups.do",
	  	type:"post",
	  	dataType:"json",
	    data:{
		    "linkManId":linkManId,
		    "linkGroups":checkBox,
       },
       success: function(result){
    	   var result = result.data;
    	   if(result.indexOf("success")==0){
    		   parent.layer.msg('保存成功！', {icon : 1});  		
    		   closeWindow();
    	   }else{
    		   parent.layer.msg('保存失败！'); 
    		   closeWindow();
    	   }
       }
	});
}


/**复选框 
 * @param f
 */
function  manucheck(f){
     var id=$(f).attr("nodeId");
     if($(f).attr('checked')){
    	 groupId.push(id);
     }else{
    	 var index = resourceIds.indexOf(id);
    	 if (index > -1) {
    		 groupId.splice(index, 1);
          }
	}
}




/**复选框全选后操作
 * @param f
 */
function afterSelectAll(f){	
	 var divID=$(f).attr("divID");
	 $("input[type='checkbox'][divID='"+divID+"'][nodeId]").each(function (){
		 var index = groupId.indexOf($(this).attr("nodeId"));
		 if($(f).attr('checked')){
			 //判断数组中是否含有  不含有再添加			
	    	 if (index == -1) {
	    		 groupId.push($(this).attr("nodeId"));
	          }			
	     }else{	    	
	    	 if (index > -1) {
	    		 groupId.splice(index, 1);
	          }
		} 
	 });   
}

